﻿using Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InstallWizard.Model
{
    public class AppInfo
    {
        public string AppName { get; set; }
        public string AppVer { get; set; }
        public string DotnetVersion { get; set; }
        public string AppDesc { get; set; }
        public string AppLogoFileName { get; set; }
        public string AppLicenseFile { get; set; }
        public string DotNetFrameworkFile { get; set; }
        public string CompanyName { get; set; }
        public float Size_MB { get; set; }
        public string GetAppNameVer()
        {
            return AppName + " " + AppVer;
        }
        public string GetLicense()
        {
            if(File.Exists(AppLicenseFile))
            {
                return File.ReadAllText(AppLicenseFile);
            }
            else
            {
                return null;
            }
        }
        public void LoadFromFile(string file)
        {
           
            if (File.Exists(file))
            {
                MyConfiguration cfg = new MyConfiguration(file);
               
                if (cfg.ContainsKey(CfgItems.AppName))
                {
                    AppName = cfg.ReadString(CfgItems.AppName);
                }
                if (cfg.ContainsKey(CfgItems.AppVer))
                {
                    AppVer = cfg.ReadString(CfgItems.AppVer);
                }

                if (cfg.ContainsKey(CfgItems.AppLogoFileName))
                {
                    AppLogoFileName = cfg.ReadString(CfgItems.AppLogoFileName);
                }
                if (cfg.ContainsKey(CfgItems.AppDesc))
                {
                    AppDesc = cfg.ReadString(CfgItems.AppDesc);
                }
                if (cfg.ContainsKey(CfgItems.CLRVer))
                {
                    AppDesc = cfg.ReadString(CfgItems.CLRVer);
                }
            }
        }
    }
}
